from functools import reduce, partial

# 匿名函数
print((lambda x, y: x * y)(2, 3))

g = (lambda x, y: x * y)
print(g(2, 3))


def f(x):   # 高阶函数
    return x * x


print(list(map(f, (1, 2, 3))))


def m(x, y):
    return x * y


print(reduce(m, (1, 3, 4)))


def is_odd(n):
    return n % 2 == 1


print(list(filter(is_odd, [1, 2, 3, 4, 5])))


def title(topic, part):
    return topic + ":" + part


print(partial(title, u"Python基础")(u"开篇"))  # 偏函数


def demo(num, *args, **kwargs):
    print(num)
    print(args)
    print(kwargs)


demo("num", 1, 2, 3, name="张三", age=14)
